package com.hspedu.newData.dmsxl.链表.合并链表;

import com.hspedu.newData.dmsxl.ds.ListNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-27 
 * @Version: 1.0
 */

public class LC21合并两个有序链表 {

    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode dummy = new ListNode();
        ListNode cur = dummy;
        while(list1 != null && list2 != null){
            if (list1.val <= list2.val){
                dummy.next = list1;
                list1 = list1.next;
            }else {
                dummy.next = list2;
                list2 = list2.next;
            }
            dummy = dummy.next;
        }
        dummy.next = list1 == null ? list2 : list1;
        return cur.next;
    }
}
